/* Copyright (c) 2004-2022 peigen.info. All rights reserved. */

package info.peigen.hotpot.common.core.util;

import java.io.Serializable;

/**
 * <b>(Pair)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/4/13
 */
public class Pair<F, S> implements Serializable {
    private final F f;
    private final S s;

    public Pair(F k, S v) {
        this.f = k;
        this.s = v;
    }

    public static <F, S> Pair<F, S> build(F f, S s) {
        return new Pair(f, s);
    }

    public F getF() {
        return this.f;
    }

    public S getS() {
        return this.s;
    }

    @Override
    public int hashCode() {
        int prime  = 1;
        int result = 31 + (this.f == null ? 0 : this.f.hashCode());
        result = 31 * result + (this.s == null ? 0 : this.s.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        } else if (obj == null) {
            return false;
        } else if (this.getClass() != obj.getClass()) {
            return false;
        } else {
            Pair other = (Pair) obj;
            if (this.f == null) {
                if (other.f != null) {
                    return false;
                }
            } else if (!this.f.equals(other.f)) {
                return false;
            }

            if (this.s == null) {
                if (other.s != null) {
                    return false;
                }
            } else if (!this.s.equals(other.s)) {
                return false;
            }

            return true;
        }
    }

    @Override
    public String toString() {
        return "Pair <" + this.f + "," + this.s + ">";
    }
}